package com.wx.wxapp.service;


import com.wx.wxapp.dao.FoodMapper;
import com.wx.wxapp.dao.UserMapper;
import com.wx.wxapp.entity.Food;
import com.wx.wxapp.entity.User;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FoodService {
    @Autowired
    private SqlSessionFactory sqlSessionFactory;

    public List<Food> getFoodCard(String openid){
        SqlSession sqlSession = sqlSessionFactory.openSession();
        FoodMapper foodMapper = sqlSession.getMapper(FoodMapper.class);
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);

        User user = userMapper.selectByOpenid(openid);
        int id = user.getId();

        List<Food> foodcards = foodMapper.selectByUserId(id);

        sqlSession.close();
        return foodcards;


    }

}
